Return * for n number of times


Posted by Christy on 2022-04-19

Description: Write a function that accepts a number n and returns * for n number of times

function star(n) {

}

console.log(star(3)); // ***
function star(n) {
  let result = "";
  for (let i = 1; i <= n; i++) {
    result += "*";
  }
  return result;
}

console.log(star(3));

Be careful about the way of ouput, if it's print -> console.log; if it's return -> return










Related Posts

FPGA 基本與設計的一些要點

FPGA 基本與設計的一些要點

[ 學習筆記系列 ] 很基礎的 JavaScript 入門 (二) - ES6 語法與 Module

[ 學習筆記系列 ] 很基礎的 JavaScript 入門 (二) - ES6 語法與 Module

Angular 入門教學 - 系列文目錄

Angular 入門教學 - 系列文目錄


Comments